#!/bin/bash
#####		CCAA管理脚本			#####
#####		Author:xiaoz.me			#####
#####		Update:2017-12-08		#####

#导入环境变量
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin
export PATH

aria2pid=$(pgrep 'aria2c')
caddypid=$(pgrep 'caddy')

case $1 in
	'start')
		nohup aria2c --conf-path=/etc/ccaa/aria2.conf > /etc/ccaa/aria2.log 2>&1 &
		nohup caddy -conf="/etc/ccaa/caddy.conf" > /etc/ccaa/caddy.log 2>&1 &
		exit
	;;
	'stop')
		kill -9 ${aria2pid}
		kill -9 ${caddypid}
	;;
	'restart')
		kill -9 ${aria2pid}
		kill -9 ${caddypid}
		nohup aria2c --conf-path=/etc/ccaa/aria2.conf > /etc/ccaa/aria2.log 2>&1 &
		nohup caddy -conf="/etc/ccaa/caddy.conf" > /etc/ccaa/caddy.log 2>&1 &
		exit;
	;;
	'status')
		if [ "$aria2pid" == "" ]
			then
				echo "Not running!"
			else
				echo '-----------------------------------------------'
				echo "Aria2 is running,pid is ${aria2pid}."
				echo "Caddy is running,pid is ${caddypid}."
				echo '-----------------------------------------------'
		fi
	;;
	*)
		echo '参数错误！'
		exit
	;;
esac